'''
https://leetcode.cn/problems/max-consecutive-ones-i
'''
from typing import List


class Solution:
    def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
        n = len(nums)
        l = r = 0
        flag = True
        res = 0
        while l < n:
            while r < n and (nums[r] == 1 or flag):
                if nums[r] == 0: flag = False
                r += 1
            # r 多走一步
            res = max(res, r - l)
            if nums[l] == 0:
                flag = True
            l += 1
        return res